home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / fntool / writefnt.c < prev   
Text File  |  1993-12-06  |  2KB  |  91 lines

  1. #include "fntool.h"
  2. #include "../include/grx.h"
  3. #include "../include/grxfile.h"
  4.  
  5. static long bitmapsize(void)
  6. {
  7.     chr  *cp;
  8.     long total = 0;
  9.  
  10.     for(cp = fnt.chars; cp != NULL; cp = cp->next)
  11.         total += (cp->width + 7) >> 3;
  12.     return(total * fnt.height);
  13. }
  14.  
  15. static void writeheader(void)
  16. {
  17.     FntFileHdr fhdr;
  18.  
  19.     memset(&fhdr,0,sizeof(fhdr));
  20.     fhdr.magic = FONT_MAGIC;
  21.     fhdr.bitmapsize = bitmapsize();
  22.     fhdr.h.fnt_isfixed  = fnt.isfixed;
  23.     fhdr.h.fnt_width    = fnt.avgwidth;
  24.     fhdr.h.fnt_height   = fnt.height;
  25.     fhdr.h.fnt_minchar  = fnt.minchar;
  26.     fhdr.h.fnt_maxchar  = fnt.maxchar;
  27.     fhdr.h.fnt_internal = 0;
  28.     fhdr.h.fnt_baseline = fnt.baseline;
  29.     fhdr.h.fnt_undwidth = fnt.undwidth;
  30.     strcpy(fhdr.h.fnt_name,fnt.name);
  31.     strncpy(fhdr.h.fnt_family,fnt.family,15);
  32.     fhdr.h.fnt_family[15] = '\0';
  33.     if((fnt.weight[0] != '\0') || (fnt.slant[0] != '\0'))
  34.         fhdr.h.fnt_family[15-5] = '\0';
  35.     if((fnt.weight[0] != '\0') && (fnt.slant[0] != '\0'))
  36.         fhdr.h.fnt_family[15-10] = '\0';
  37.     if(fnt.weight[0] != '\0') {
  38.         strcat(fhdr.h.fnt_family,"_");
  39.         strcat(fhdr.h.fnt_family,fnt.weight);
  40.     }
  41.     if(fnt.slant[0] != '\0') {
  42.         strcat(fhdr.h.fnt_family,"_");
  43.         strcat(fhdr.h.fnt_family,fnt.slant);
  44.     }
  45.     fwrite(&fhdr,sizeof(fhdr),1,outfile);
  46. }
  47.  
  48. static void writewidthtable(void)
  49. {
  50.     short wdt[1];
  51.     chr   *cp;
  52.  
  53.     for(cp = fnt.chars; cp != NULL; cp = cp->next) {
  54.         wdt[0] = (short)cp->width;
  55.         fwrite(wdt,sizeof(short),1,outfile);
  56.     }
  57. }
  58.  
  59. static void writebitmap(void)
  60. {
  61.     int xx,yy,wdt;
  62.     int bits,mask;
  63.     chr *cp;
  64.  
  65.     for(cp = fnt.chars; cp != NULL; cp = cp->next) {
  66.         wdt = cp->width;
  67.         for(yy = 0; yy < fnt.height; yy++) {
  68.         bits = 0;
  69.         mask = 0x100;
  70.         for(xx = 0; xx < wdt; xx++) {
  71.             if((mask >>= 1) == 0) {
  72.             putc(bits,outfile);
  73.             bits = 0;
  74.             mask = 0x80;
  75.             }
  76.             if(cp->bmp[yy][xx] != 0) bits |= mask;
  77.         }
  78.         putc(bits,outfile);
  79.         }
  80.     }
  81. }
  82.  
  83. void writefnt(void)
  84. {
  85.     writeheader();
  86.     if(!fnt.isfixed) writewidthtable();
  87.     writebitmap();
  88.     fputs(notes,outfile);
  89. }
  90.  
  91.